<!DOCTYPE html>
<html>

<head>
    <title>短信账号管理</title>
    <include file='public/head'>
        <style>
            table th,
            table td {
                text-align: center;
            }

            .ml-10 {
                margin-left: 10px;
            }
        </style>
</head>

<body>

    <div class="wrap js-check-wrap">
        <ul class="nav nav-tabs">
            <php> $currentTab = 1;</php>
            <include file="public/nav" />
        </ul>

        <form class="well form-inline margin-top-20">
            <select type="text" name="condition1" class="form-control">
                <option value="1" <?php if($search['condition1']==1){echo 'selected';}  ?> >用户id</option>
                <option value="2" <?php if($search['condition1']==2){echo 'selected';}  ?> >用户帐号</option>
            </select>
            <input type="text" class="form-control" name="keyword" style="width:200px;" value="{$search.keyword}"
                placeholder="输入关键词" />

            <input type="submit" class="btn btn-primary" value="搜索" />
        </form>
        <form>
            <table class="table table-bordered table-hover" zIndex="100">
                <thead>
                    <tr class="theader">
                        <th>ID</th>
                        <th>用户ID</th>
                        <th>用户帐号</th>
                        <th>用户密码</th>
                        <th>条数</th>
                        <th>备注</th>
                        <th>操作 &nbsp;
                            <a href="javascript:;" class="btn btn-success btn-sm add-config-btn" onclick="add();">
                                <i class="fa fa-plus-circle normal"></i> 添加账号
                            </a>
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <volist name="account_list" id="vo">
                        <tr>
                            <td>{$vo.id}</td>
                            <td>{$vo.uid}</td>
                            <td>{$vo.account}</td>
                            <td>{$vo.password}</td>
                            <td>{$vo.total_num-$vo.consume_num}/{$vo.total_num}</td>
                            <td>{$vo.remark}</td>
                            <td>
                                <a class="btn btn-sm btn-success  " onclick="addNum({$vo.id})">增加条数</a>
                                <a class="btn btn-sm btn-success  " onclick="edit({$vo.id})">修改</a>
                                <a class="btn btn-sm btn-info " onclick="detail({$vo.id})">查看</a>
                                <a href="{:cmf_plugin_url('SmsAccount://sms_account/delete')}?id={$vo.id}" class="btn btn-sm btn-danger js-ajax-delete" data-msg="确定删除吗？">删除</a>
                            </td>
                        </tr>
                    </volist>
                </tbody>
            </table>
            <div class="pagination">{$page|default=''}</div>

        </form>
    </div>





    <include file='public/scripts'>
        <script src="__STATIC__/js/layer/layer.js"></script>
        <script src="__STATIC__/js/custom/custom.js"></script>

        <!-- 弹出层 -->
        <script type="text/javascript">

            /**
             * 添加会员
             */
            function add() {
                let add_url = "{:cmf_plugin_url('SmsAccount://sms_account/add')}";
                layer.open({
                    type: 2,
                    title: '添加账号',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['600px', '700px'],
                    btn: ['提交', '关闭'],
                    fixed: false,
                    content: add_url, //iframe的url
                    yes: function (index, layero) {
                        var body = layer.getChildFrame('body', index);

                        parentInfo = window["layui-layer-iframe" + index].callbackdata();
                        // console.log(parentInfo);

                        if (parentInfo==false) {
                            return false;
                        }
                        $.ajax({
                            url: add_url,
                            type: 'post',
                            data: parentInfo,
                            dataType: 'json',
                            success: function (data) {
                                if (data.status == 'success') {
                                    layer.msg(data.message, { time: 2000 }, function () {
                                        window.location.reload();
                                        layer.closeAll();
                                    });
                                } else if (data.status == 'error') {
                                    layer.msg(data.message);
                                }
                            },
                            error: function (data) {
                                layer.message('添加失败');
                                return false;
                            }
                        })
                    }

                });
            }

            /**
             * 修改
             */
            function edit(data) {
                let edit_url = "{:cmf_plugin_url('SmsAccount://sms_account/edit')}?id=" + data;
                layer.open({
                    type: 2,
                    title: '修改',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['600px', '700px'],
                    btn: ['提交', '关闭'],
                    fixed: false,
                    content: edit_url, //iframe的url
                    yes: function (index, layero) {
                        var body = layer.getChildFrame('body', index);

                        parentInfo = window["layui-layer-iframe" + index].callbackdata();
                        console.log(parentInfo);

                        if (parentInfo == false) {
                            return false;
                        }

                        $.ajax({
                            url: edit_url,
                            type: 'post',
                            data: parentInfo,
                            dataType: 'json',
                            success: function (data) {
                                if (data.status == 'success') {
                                    layer.msg(data.message, { time: 2000 }, function () {
                                        window.location.reload();
                                        layer.closeAll();
                                    });
                                } else if (data.status == 'error') {
                                    layer.msg(data.message);
                                }
                            },
                            error: function (data) {
                                layer.message('添加失败');
                                return false;
                            }
                        })
                    }
                });
            }

            /**
             * 增加条数
             */
            function addNum(data) {
                let edit_url = "{:cmf_plugin_url('SmsAccount://sms_account/addNum')}?id=" + data;
                layer.open({
                    type: 2,
                    title: '增加条数',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['650px', '700px'],
                    btn: ['提交', '关闭'],
                    fixed: false,
                    content: edit_url, //iframe的url
                    yes: function (index, layero) {
                        var body = layer.getChildFrame('body', index);

                        parentInfo = window["layui-layer-iframe" + index].callbackdata();
                        console.log(parentInfo);

                        if (parentInfo == false) {
                            return false;
                        }

                        $.ajax({
                            url: edit_url,
                            type: 'post',
                            data: parentInfo,
                            dataType: 'json',
                            success: function (data) {
                                if (data.status == 'success') {
                                    layer.msg(data.message, { time: 2000 }, function () {
                                        window.location.reload();
                                        layer.closeAll();
                                    });
                                } else if (data.status == 'error') {
                                    layer.msg(data.message);
                                }
                            },
                            error: function (data) {
                                layer.message('添加失败');
                                return false;
                            }
                        })
                    }
                });
            }
            /**
             * 查看会员
             */
            function detail(data) {
                let url = "{:cmf_plugin_url('SmsAccount://sms_account/detail')}?id=" + data;

                layer.open({
                    type: 2,
                    title: '查看信息',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['600px', '600px'],
                    btn: ['关闭'],
                    fixed: false,
                    content: url
                });
            }


        </script>



</body>

</html>